package _18注解案例_模拟Test注解;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获得Class对象
        Class<Worker> workerClass = Worker.class;
        //通过反射构造方法对象获取对象
        Worker worker = workerClass.getConstructor().newInstance();
        //通过Class对象获得所有方法对象
        Method[] methods = workerClass.getMethods();
        for (Method m : methods) {
            //判断方法上是否有标记MyTest注解
            if (m.isAnnotationPresent(MyTest.class)){
                m.invoke(worker);
            }
        }


    }
}
